<{capture name="header"}>
  <{script src="treelist.js" app="ectools"}>
<{/capture}>
<div id="dltype-info-<{$dt_id}>">
<div style="text-align:right;"><{help docid="69" type="link"}><{t}>点击查看帮助<{/t}><{/help}></div>
<h3 class="head-title"><{t}>添加配送方式<{/t}></h3>


<form action="index.php?app=b2c&ctl=admin_dlytype&act=saveDlType" id="dtypeForm" method="post" class="tableform">
<div class="division">
<!--copyDtype delete begin-->
<{if $dt_info.dt_id}>
	<input type="hidden" name="dt_id" id="aEditor-Garticleid-input" value="<{$dt_info.dt_id}>" />

<{else}>
	<input type="hidden" name="dt_id" id="aEditor-Garticleid-input" value="" />
<{/if}>
<!--copyDtype delete end-->

<!--tag_foreign_dt_id-->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th><em class="red">*</em><{t}>配送方式名称：<{/t}></th>
    <td><input type="text" name="dt_name" value="<{$dt_info.dt_name}>" vtype="required" class="_x_ipt" caution="<{t}>请填写配送方式名称<{/t}>" maxlength="20"></td>

  </tr>
    <tr>
    <th><{t}>选择默认物流公司：<{/t}></th>
    <td>
      <select name="corp_id">
        <option value="0"><{t}>请选择物流公司<{/t}></option>
      <{foreach from=$clist item=corp}>
        <option value='<{$corp.corp_id}>' <{if $dt_info.corp_id == $corp.corp_id}>selected<{/if}>><{$corp.name}></option>
      <{/foreach}>
      </select>
    </td>
  </tr>

  <!--delete begin-->
  <tr>
    <th><{t}>类型：<{/t}></th>
    <td><label><input type="radio" name="has_cod" value="0" <{if $dt_info.has_cod == 'false' or $dt_info == ""}>checked<{/if}>><{t}>先收款后发货<{/t}></label>      <br />
    <label><input type="radio" name="has_cod" value="1" <{if $dt_info.has_cod == 'true'}>checked<{/if}>><{t}>货到付款<{/t}></label><span class="notice-inline"><{t}>选择货到付款后顾客无需再选择支付方式<{/t}></span></td>
  </tr>
  <!--delete end-->

  <tr>
    <th><{t}>重量设置：<{/t}></th>
  <!--delete begin-->
    <td><{t}>首重重量<{/t}>&nbsp;<select name="firstunit" ><{html_options options=$weightunit selected=$dt_info.firstunit}></select>&nbsp;<{t}>续重单位<{/t}>&nbsp;<select name="continueunit"><{html_options options=$weightunit  selected=$dt_info.continueunit}></select></td>
  <!--delete end-->

  <!--tag_foreign_unit-->
    <th>&nbsp;</th><td>&nbsp;</td>
  </tr>

  <tr>
    <th>&nbsp;</th>
    <td><input type="checkbox" name="protect" value="1" <{if $dt_info.protect=='true'}>checked<{/if}>><{t}>支持物流保价<{/t}>
    <script>
               $E('#dltype-info-<{$dt_id}> input[name=protect]').addEvent('click',function(){
                    if(this.checked){
                        $('protect_rate').show().getFormElements().set('disabled',false);
                    }else{
                      $('protect_rate').hide().getFormElements().set('disabled',true);
                    }               
               });
        $E('#dltype-info-<{$dt_id}> input[name=protect]')
        .fireEvent('click',$E('#dltype-info-<{$dt_id}> input[name=protect]'));

		  </script>
    </td>
    <th>&nbsp;</th><td>&nbsp;</td>
  </tr>
  <tr id="protect_rate">
    <th><{t}>保价设置：<{/t}></th>
    <td>
       <{t}> 费率<{/t}>&nbsp;<input type="text" name="protect_rate" value="<{$dt_info.protect_rate}>" style="width:25px;" class='_x_ipt' vtype='required&&number' caution="<{t}>该项必填且只允许填写数字金额<{/t}>">%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{t}>最低保价费<{/t}>&nbsp;<input type="text" name="minprice" value="<{$dt_info.minprice}>" style="width:25px;" class='_x_ipt' vtype='required&&number' caution="<{t}>该项必填且只允许填写数字金额<{/t}>">
    </td>
    <th>&nbsp;</th><td>&nbsp;</td>
  </tr>
  <tr>
    <th><{t}>地区费用类型：<{/t}></th>
    <td>
    <div id='deliveryAreaToggle'>
      <label><input type="radio" name="setting" value='1' <{if $dt_info.setting=="1"||$dt_info.setting==""}>checked<{/if}>><{t}>统一设置<{/t}></label><br /><label><input type="radio" name="setting" value='0' <{if $dt_info.setting=="0"}>checked<{/if}>><{t}>指定配送地区和费用<{/t}></label>
    </div>    
    <script>
          
          function deliveryAreaToggle(radio){
                 var tradio=radio;
                 var tradioValue=tradio.get('value');
                 var tmap={
                       '1':$('def_dexp'),
                       '0':$('deliveryAreabox')
                     };
                  if(tradio.checked){
                    tmap[tradioValue].show();
                    $('def_area_dexp').show().getFormElements().set('disabled',false);
                    tmap[tradioValue].getFormElements().set('disabled',false);
                  }else{
                    tmap[tradioValue].hide();
                    $('def_area_dexp').hide().getFormElements().set('disabled',true);

                    tmap[tradioValue].getFormElements().set('disabled',true);
                  }
          }
       
       </script>
    
    </td>
    <th>&nbsp;</th><td>&nbsp;</td>
  </tr>
  <!--tag_foreign_dtype_other_surcharge-->

    </table>
   </div>

<div class="division" id='def_dexp'>   
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <input type="hidden" name="price" value=0>
  <tr class="b-tp">
    <th style="padding-top:13px"><{t}>配送费用：<{/t}></th>
    <td>
    <div class='deliveryexpbox'>
      <div class='deliveryexp' style="<{if $dt_info.dt_useexp==1}>display:none<{/if}>">
                <{t}>首重费用<{/t}> <input style="width:30px;" type='text' name='firstprice' value="<{$dt_info.firstprice}>" class="_x_ipt" vtype="required&&number" caution="<{t}>该项必填且只允许填写数字金额<{/t}>"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               <{t}> 续重费用<{/t}> <input style="width:30px;" type='text' name='continueprice' value="<{$dt_info.continueprice}>" class="_x_ipt" vtype="required&&number" caution="<{t}>该项必填且只允许填写数字金额<{/t}>"/>
			   <{if !$is_delivery_discount_close}>
				<{t}>邮寄折扣 <{/t}><input style="width:30px;" type='text' name='dt_discount' value="<{$dt_info.dt_discount}>" class="_x_ipt" vtype="required&&number" caution="<{t}>该项必填且只允许填写数字金额<{/t}>"/>
				<{/if}>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>使用公式<{/t}></span>
                
     </div>
      <div class='deliveryexp' style='<{if $dt_info.dt_useexp==0}>display:none<{/if}>'>
                  <{t}>配送公式<{/t}> <input style="width:300px;" type='text' name='dt_expressions' value="<{if $dt_info.dt_useexp}><{$dt_info.dt_expressions}><{/if}>"  class="_x_ipt" vtype="required&&checkExp1&&checkExp2" /><{button label=$___b2c="验证"|t:'b2c' class="checkexp" onclick="checkExp(this);"}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>取消公式<{/t}></span>
				  <input type="hidden" name="dt_useexp" value="<{$dt_info.dt_useexp}>">
       </div>  
      </div> 
    </td>
  </tr>
  </table>
  </div>
  <div class="division" id='def_area_dexp'>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="b-tp">
        <tr >
            <th>&nbsp;</th>
            <td><input type="checkbox" name="def_area_fee" value="1" <{if $dt_info.def_area_fee=='true'}>checked<{/if}>><{t}>启用默认费用<{/t}><span class="notice-inline"><!--delete begin--><{t}>注意：未启用默认费用时，不在指定配送地区的顾客不能使用本配送方式下订单<{/t}><!--delete end--><!--tag_foreign_zhuiyi--></span></td>
          <script>

               $E('#dltype-info-<{$dt_id}> input[name=def_area_fee]').addEvent('click',function(){
                    
                    if(this.checked){
                        $('area_dexp').show().getFormElements().set('disabled',false);
                    }else{
                      $('area_dexp').hide().getFormElements().set('disabled',true);
                    }
               
               });
        $E('#dltype-info-<{$dt_id}> input[name=def_area_fee]').fireEvent('click',$E('#dltype-info-<{$dt_id}> input[name=def_area_fee]'));
         $$("#deliveryAreaToggle input[name=setting]").addEvent('click',function(){
				
			$$("#deliveryAreaToggle input[name=setting]").each(deliveryAreaToggle);
        }).each(deliveryAreaToggle);
          </script>
        </tr>
        <tr id="area_dexp">
            <th>&nbsp;</th>
            <td>
                <div class='deliveryexpbox'>
                <div class='deliveryexp' style="<{if $dt_info.dt_useexp==1}>display:none<{/if}>">
               <{t}> 首重费用<{/t}> <input type="text" name="firstprice" id="firstprice" value="<{$dt_info.firstprice}>" style="width:30px;" class='_x_ipt' vtype='required&&number' caution="<{t}>该项必填且只允许填写数字金额<{/t}>"><{t}>&nbsp;续重费用<{/t}><input type="text" name="continueprice" id="continueprice" value="<{$dt_info.continueprice}>" style="width:30px;" class='_x_ipt' vtype='required&&number' caution="<{t}>该项必填且只允许填写数字金额<{/t}>">
			   <{if !$is_delivery_discount_close}>
				<{t}>&nbsp;邮寄折扣<{/t}><input type="text" name="dt_discount" id="dt_discount" value="<{$dt_info.dt_discount|default:1}>" style="width:30px;" class='_x_ipt' vtype='required&&number' caution="<{t}>该项必填且只允许填写数字金额<{/t}>">
				<{/if}>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>使用公式<{/t}></span>
                </div>
                <div class='deliveryexp' style='<{if $dt_info.dt_useexp==0}>display:none<{/if}>'>
                 <{t}> 配送公式<{/t}> <input style="width:300px;" type='text' name='dt_expressions' value="<{$dt_info.dt_expressions}>"  class="_x_ipt" vtype="required&&checkExp1&&checkExp2" /><{button label=$___b2c="验证"|t:'b2c' class="checkexp" onclick="checkExp(this);"}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>取消公式<{/t}></span>
                  <input type="hidden" name="dt_useexp" value="<{$dt_info.dt_useexp}>">
                </div> 
                </div>
            </td>
        </tr>
    </table>
  </div>
  
  <div class="division" id='deliveryAreabox'>
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th><{t}>支持的配送地区:<{/t}></th>
    <td>
        <div  id="deliveryArea-<{$dt_info.dt_id}>" class='deliveryArea' style="background:#f8f8f8; border:1px solid #ccc;">
           <ol>
           
           <{if $dt_info.area_fee_conf}>
           <input type='hidden' name='delidgroup'/>
               <script>
                       function deleteDelivery(d){
                          if (!confirm('<{t}>删除后无法恢复，确定要删除吗？<{/t}>')){
                            return;
                          }
                          var areaid_group=d.getElement('input[name^=area_fee_conf]');
                          var delidgroupHidden=$E('#deliveryArea-<{$dt_info.dt_id}> input[name=delidgroup]');
                          var _id;
                          areaid_group.get('name').replace(/\[(\d+)?\]/,function($0,$1){
                                _id=$1;   
                          });
                          if(_id){
                                delidgroupHidden.value+=(delidgroupHidden.value!=''?",":'')+_id;
                          }
                          d.dispose();
                         }
               </script>
             <{foreach from=$dt_info.area_fee_conf item=area key=key}>
             <li class='division' style="list-style:decimal; margin-left:15px;">
                <div class='deliverycity'>
                                 <span style="float:right;" onclick='deleteDelivery($(this).getParent("li"))'><{img app="desktop" src='bundle/delete.gif' style='cursor:pointer;' alt=$___b2c="删除"|t:'b2c'}></span>
                <{t}>配送地区<{/t}> <input style="width:300px;" type='text' name='area_fee_conf[<{$key}>][areaGroupName]' readonly=true required="true" value='<{$area.areaGroupName}>' class="_x_ipt" vtype="required" caution="<{t}>配送地区不能为空<{/t}>" onclick="regionSelect(this);">
                <input type='hidden' name='area_fee_conf[<{$key}>][areaGroupId]' value="<{$area.areaGroupId}>"/><{img class='regionSelect' src='bundle/editcate.gif' style='cursor:pointer;' onclick='regionSelect(this)' alt=$___b2c='编辑地区'|t:'b2c' title=$___b2c="编辑地区"|t:'b2c'}>
                </div>
					<div class='deliveryexpbox' acckey="<{$key}>">
						<div class='deliveryexp' style="<{if $area.dt_useexp==1}>display:none<{/if}>">
						<{t}>首重费用<{/t}> <input style="width:30px;" type='text' name='area_fee_conf[<{$key}>][firstprice]' value="<{$area.firstprice}>" <{if $area.dt_useexp=="0"}>class="_x_ipt"<{/if}> vtype="required&&number" caution="<{t}>该项必填且只允许填写数字金额<{/t}>"/>
						&nbsp;<{t}>续重费用<{/t}> <input style="width:30px;" type='text' name='area_fee_conf[<{$key}>][continueprice]' value="<{$area.continueprice}>" <{if $area.dt_useexp=="0"}>class="_x_ipt"<{/if}> vtype="required&&number" caution="<{t}>该项必填且只允许填写数字金额<{/t}>"/>
						<{if !$is_delivery_discount_close}>
						<{t}>&nbsp;邮寄折扣<{/t}><input type="text" name="area_fee_conf[<{$key}>][dt_discount]" value="<{$area.dt_discount|default:1}>" style="width:30px;" class='_x_ipt' vtype='required&&number' caution="<{t}>该项必填且只允许填写数字金额<{/t}>">
						<{/if}>
						&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>使用公式<{/t}></span>
							</div>
						<div class='deliveryexp' style='<{if $area.dt_useexp==0}>display:none<{/if}>'>

						 <{t}> 配送公式<{/t}> <input style="width:300px;" type='text' name='area_fee_conf[<{$key}>][expressions]' value="<{$area.dt_expressions}>" <{if $area.dt_useexp=="1"}>class="_x_ipt"<{/if}> vtype="required&&checkExp1&&checkExp2" /><{button label=$___b2c="验证"|t:'b2c' class="checkexp" onclick="checkExp(this);"}>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>取消公式<{/t}></span> 

						  <input type='hidden' name='area_fee_conf[<{$key}>][dt_useexp]' value='<{$area.dt_useexp}>'/>
						</div>
					</div>
               
             </li>
             <{/foreach}>
            <{else}>


            <{/if}>
           </ol>
           <{button label=$___b2c="为指定的地区设置运费"|t:'b2c' class="add-dlyarea" }>
        </div>
    </td>
  </tr>
    </table>
    </div>
    
    <div class="division b-tp">
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <th><{t}>排序：<{/t}></th>
                <td>
                    <input  type="text" vtype="unsignedint" name="ordernum" id="ordernum" value="<{$dt_info.ordernum}>" size=5 caution="<{t}>请输入排序项，并且为正整数<{/t}>" class="_x_ipt"/>
                </td>
            </tr>
            <tr>
                <th><{t}>状态：<{/t}></th>
                <td><input type="radio" name="dt_status" <{if $dt_info.dt_status=="1"||$dt_info.dt_status==""}>checked<{/if}> value="1"><{t}>启用<{/t}><br /><input type="radio" name="dt_status" value="0" <{if $dt_info.dt_status=="0"}>checked<{/if}>><{t}>关闭<{/t}></td>
            </tr>
         </table>
  </tr>
    </div>
    
    <div class="division b-tp">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <th><{t}>详细介绍：<{/t}></th>
    <td><{input type="html" name="detail" value=$dt_info.detail}></td>
  </tr>
    </table>
    </div>

</form>
</div>


<script>
/*var DialogExp ;
$ES(".checkexp","area-tbody-dom").each(function(item, index, itobj){
  item.addEvent('click',function(e){
    e=new Event(e);
    var ipt=e.target;
    var id = 'check_'+ipt.getAttribute('areaid');
    DialogExp = new Dialog('index.php?app=b2c&app=ectools&ctl=regions&act=checkExp&area_id='+ipt.getAttribute('areaid')+'&expvalue='+encodeURIComponent($(id).value),{modal:true,title:'验算配送公式'});
  });
});*/

validatorMap.set('checkExp1',['<{t}>公式中含有非法字符<{/t}>',function(e,v){
           return !(new RegExp("/^[^\]\[\}\{\)\(0-9WwPp\+\-\/\*]+$/")).test(v);
   }]);
validatorMap.set('checkExp2',['<{t}>公式格式不正确<{/t}>',function(e,v){
           var price = 100;
           var weight = 100;
           var str ;
              str = v.replace(/(\[)/g, "getceil(");
              str = str.replace(/(\])/g, ")");
              str = str.replace(/(\{)/g, "getval(");
              str = str.replace(/(\})/g, ")");
              str = str.replace(/(W)/g, weight);
              str = str.replace(/(w)/g, weight);
              str = str.replace(/(P)/g, price);
              str = str.replace(/(p)/g, price);
          try {
            eval(str);
            return true;
          }catch(e){
            return false;
          }
   }]);


function saveDt(){
   $ES('textarea[ishtml=true]',$('dltype-info-<{$dt_info.dt_id}>')).getValue();
   W.page('index.php?app=b2c&app=ectools&ctl=regions&act=saveDlType',{data:$('dltype-info-<{$dt_info.dt_id}>'),method:'post'})
}
function getval(expval){
  if (eval(expval) > 0.000001){
    return 1;
  }else if (eval(expval) >-0.000001&&eval(expval)< 0.000001){
    return 1/2;
  }else{
    return 0;
  }
}
function getceil(expval){
  if (eval(expval) > 0){
    return Math.ceil(eval(expval)-0.000001);
  }else{
    return 0;
  }
}


       function chaexps(el){
        var  dexpsbox = $(el).getParent('.deliveryexpbox');
		var arr_depxs = dexpsbox.getElements('.deliveryexp');
		arr_depxs.each(function(obj){			
			obj.setStyle('display','none'==obj.getStyle('display')?'':'none');
			if (obj.getElement('input[name^=useexp]'))
			{
				if (!obj.isDisplay())
				{
					obj.getElement('input[name^=useexp]').set('value',0);
				}
				else
				{
					obj.getElement('input[name^=useexp]').set('value',1);
				}
			}
			
			if (obj.getElement('input[name^=dt_useexp]'))
			{
				if (!obj.isDisplay())
				{
					obj.getElement('input[name^=dt_useexp]').set('value',0);
				}
				else
				{
					obj.getElement('input[name^=dt_useexp]').set('value',1);
				}
			}
			
			if (obj.getElement('input[name^=\'area_fee_conf[' + dexpsbox.get('acckey') + '][useexp]\']'))
			{
				if (!obj.isDisplay())
				{
					obj.getElement('input[name^=\'area_fee_conf[' + dexpsbox.get('acckey') + '][useexp]\']').set('value',0);
				}
				else
				{
					obj.getElement('input[name^=\'area_fee_conf[' + dexpsbox.get('acckey') + '][useexp]\']').set('value',1);
				}
			}
			
			if (obj.getElement('input[name^=\'area_fee_conf[' + dexpsbox.get('acckey') + '][dt_useexp]\']'))
			{
				if (!obj.isDisplay())
				{
					obj.getElement('input[name^=\'area_fee_conf[' + dexpsbox.get('acckey') + '][dt_useexp]\']').set('value',0);
				}
				else
				{
					obj.getElement('input[name^=\'area_fee_conf[' + dexpsbox.get('acckey') + '][dt_useexp]\']').set('value',1);
				}
			}
			
		});
         /*   dexps.each(function(i){
               if(i.getElement('input[name^=useexp]')){
                   if(!i.isDisplay()){
                     i.getElement('input[name^=useexp]').set('value',0);
                   }else{
                    i.getElement('input[name^=useexp]').set('value',1);
                   }
               }
               else if (i.getElement('input[name^=dt_useexp]'))
               {
                   if(!i.isDisplay()){
                     i.getElement('input[name^=dt_useexp]').set('value',0);
                   }else{
                    i.getElement('input[name^=dt_useexp]').set('value',1);
                   }
               }
            });*/
       }
 
       void function(){
            var btn_add=$E('#deliveryArea-<{$dt_info.dt_id}> .add-dlyarea');
			
            var getItemTemplete=function(){
			var key = $ES('#deliveryArea-<{$dt_info.dt_id}> .division ').length + 1;
            var btn = '<{button label=$___b2c="验证"|t:"b2c" class="checkexp" onclick="checkExp(this);"}>';
            var itemTemplete = "<div class='deliverycity'>";
                itemTemplete += "<span style='float:right;' onclick='";
                itemTemplete += "if(!confirm(\"<{t}>删除后无法恢复,确定要删除吗?<{/t}>\"))return;$(this).getParent(\"li\").remove();' ";
                itemTemplete += '><{img app="desktop" src="bundle/delete.gif" style="cursor:pointer;" alt=$___b2c="删除"|t:"b2c" title=$___b2c="删除"|t:"b2c"}></span><{t}>配送地区<{/t}> ';
                itemTemplete += "<input style='width:300px;' type='text' name='area_fee_conf[" + key + "][areaGroupName]' readonly=true  value='' class='_x_ipt' vtype='required' caution='<{t}>配送地区不能为空<{/t}>' onclick=\"regionSelect(this);\">";
                itemTemplete+="<input type='hidden' name='area_fee_conf[" + key + "][areaGroupId]' value=''/>";
                itemTemplete+='<{img class="regionSelect" src="bundle/editcate.gif" style="cursor:pointer;" onclick="regionSelect(this)" alt=$___b2c="编辑地区"|t:"b2c" title=$___b2c="编辑地区"|t:"b2c"}>';
             
                itemTemplete+="</div>";
                itemTemplete+="<div class='deliveryexpbox'><div class='deliveryexp'>";
                itemTemplete+="<{t}>首重费用<{/t}> <input style='width:30px;' type='text' name='area_fee_conf[" + key + "][firstprice]' class='_x_ipt' vtype='required&&number' caution='<{t}>该项必填且只允许填写数字金额<{/t}>' value="+$('firstprice').get('value')+" >";
                itemTemplete+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{t}>续重费用<{/t}> <input style='width:30px;' type='text' name='area_fee_conf[" + key + "][continueprice]' class='_x_ipt' vtype='required&&number' caution='<{t}>该项必填且只允许填写数字金额<{/t}>' value="+$('continueprice').get('value')+" >";
				<{if !$is_delivery_discount_close}>
                itemTemplete+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<{t}>邮寄折扣<{/t}> <input style='width:30px;' type='text' name='area_fee_conf[" + key + "][dt_discount]' class='_x_ipt' value='1' vtype='required&&number' caution='<{t}>该项必填且只允许填写数字金额<{/t}>' value="+$('dt_discount').get('value')+" >";
				<{/if}>
                itemTemplete+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>使用公式<{/t}></span>";
                itemTemplete+="</div>";
                itemTemplete+="<div class='deliveryexp' style='display:none'>";
                itemTemplete+="<{t}>配送公式<{/t}> <input style='width:300px;' type='text' name='area_fee_conf[" + key + "][expressions]' value='' vtype='required&&checkExp1&&checkExp2' />";
                itemTemplete+= btn +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='lnk chgexp' onclick='chaexps(this)'><{t}>取消公式<{/t}></span>";
                itemTemplete+="<input type='hidden' name='area_fee_conf[" + key + "][dt_useexp]' value='0'/>";
                itemTemplete+="</div></div>";
             
                return  itemTemplete;
              };
            var list=$E('#deliveryArea-<{$dt_info.dt_id}> ol');
            btn_add.addEvent('click',function(){
               var newitem=new Element('li',{'class':'division','style':'line-height:30px;'}).set('html',getItemTemplete()).inject(list);
               regionSelect(newitem.getElement('.regionSelect'));
            });
            
            //$$('#dltype-info-<{$dt_id}> .chgexp').each(chaexps);
           
       }();
       function regionSelect(el){
          var el=$(el).getParent('.deliverycity');
          var iptText=el.getElement('input[type=text]');
          var iptHidden=el.getElement('input[type=hidden]');


		  new ModeDialog('index.php?app=ectools&ctl=regions&act=showRegionTreeList&p[0]='+el.uid+'&p[1]=multi',{
			  width:270,height:330,params:{iptText:iptText,iptHidden:iptHidden}});
		}

    var checkExp=function(btn){
        btn=$(btn);
        var ipt=btn.getPrevious('input');
        var expValue=ipt.getValue();
        new Dialog('index.php?app=b2c&ctl=admin_dlytype&act=checkExp&expvalue='+encodeURIComponent(expValue),
        { modal:true,
         title:'<{t}>验算配送公式<{/t}>',
         onShow:function(){

             this.dialog.store('targetIpt',ipt);
          }
        }
        );
    }

	$('dtypeForm').store('target',{
		onComplete:function(){
			if(opener.finderGroup['<{$env.get._finder.finder_id}>'])
			opener.finderGroup['<{$env.get._finder.finder_id}>'].refresh();
			window.close();
		}
	});

	subDtypeForm = function (event,sign){ 
	   var target={};
	   switch (sign){
			case 1:                    //保存不关闭
				$extend(target,{
					onComplete:function(e){
						if(window.opener.finderGroup&&window.opener.finderGroup['<{$env.get.finder_id}>'])
						window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();
						
						if(!JSON.decode(e).dt_id){
							event.target.removeProperty('disabled');
							return;
						}
						var id = JSON.decode(e).dt_id;
						if(id > 0){
							$('aEditor-Garticleid-input').value = JSON.decode(e).dt_id
						}
						event.target.disabled = false;
					}}
				);
			break;
			case 2:                   //保存关闭
				$extend(target,{
					onComplete:function(){
						if(window.opener.finderGroup&&window.opener.finderGroup['<{$env.get.finder_id}>'])
						window.opener.finderGroup['<{$env.get.finder_id}>'].refresh();
						window.close();
					}}
				);
			break;				
	   }
	    var _form=$('dtypeForm');
		if(!_form)return;
		var _formActionURL=_form.get('action'); 
		
		_form.store('target',target);
        _form.set('action',_formActionURL+'&but='+sign).fireEvent('submit',new Event(event));
    };
</script>
 
<{capture name='footbar'}>
<table cellspacing="0" cellpadding="0" style="margin:0 auto; width:100%" class="table-action">
      <tbody><tr valign="middle">
        <td>
            <{assign var="___db" value="关  闭"}>
            <{assign var="___dc" value=$___b2c='确定退出?'|t:'b2c'}>
            <{button label=$___b2c="保存并关闭窗口"|t:'b2c' class="btn-primary" onclick="subDtypeForm(event,2)"}>
            <{button label=$___b2c="保存当前"|t:'b2c' class="btn-primary" onclick="subDtypeForm(event,1)"}>
            <{button label=$___b2c=$___db|t:'b2c'  class="btn-secondary" onclick="if(confirm('{$___dc}'))window.close()"}>
        </td>
        </tr>
        </tbody></table>
<{/capture}>
